from sqlalchemy import Column, String, Boolean
from sqlalchemy.dialects.mysql import TIMESTAMP, TINYINT
from server.model import BaseOrm, engine
from pydantic import BaseModel
from datetime import datetime


class ChargeStatus:
    Not = 0
    Success = 1
    Fail = 2


class ChargeSource:
    User = 0
    System = 1
    Fix = 2


class ChargeCreate(BaseModel):
    period: str


class ChargeSchema(ChargeCreate):
    class Config:
        orm_mode = True


class Charge(BaseOrm):
    __tablename__ = 'charge'
    trans_order = Column(String(64), nullable=False, primary_key=True, comment="玩家冲卡ID")
    charge_type = Column(String(10), comment="充值对象类型: 0:用户 1:代理")
    user_id = Column(String(64), comment="用户游戏ID")
    nick_name = Column(String(64), comment="用户昵称")
    money = Column(String(64), comment="金额")
    remark = Column(String(256), comment="备注：（代给代冲卡）")
    creator = Column(String(64), comment="所属代理商id")
    creator_time = Column(TIMESTAMP, default=datetime.now, comment="冲卡时间")
    status = Column(TINYINT(unsigned=True), nullable=False, server_default="0", comment="充值状态: 0:创建订单 1:充值成功 2:充值失败")
    withdraw_limit_param = Column(TINYINT(unsigned=True), nullable=False, server_default='0', comment="提现限制参数")

    # 新增于: 2020/9/2
    before_money = Column(String(64), comment="充值前金额")
    after_money = Column(String(64), comment="充值后金额")
    is_first = Column(Boolean, nullable=False, server_default="0", comment="是否首次")
    source = Column(TINYINT(unsigned=True), nullable=False, server_default="0", comment="充值来源: 0:用户自充 1:系统充值 2:手工补单")


BaseOrm.metadata.create_all(bind=engine)
